//
//  NEDViewController.m
//  NEDViews
//
//  Created by 林宁宁 on 12/06/2021.
//  Copyright (c) 2021 林宁宁. All rights reserved.
//

#import "NEDViewController.h"
#import "UIButton+NED.h"
#import "NEDConstant.h"
#import "UIViewController+NEDBase.h"
#import "NEDSheetView.h"
#import "NEDAlertView.h"
#import "SDWebImageDownloader.h"
#import "NEDInputTextField.h"
#import "NEDTextInputNumber.h"

@interface NEDViewController ()

@end

@implementation NEDViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    WS(weakSelf)
    
    UIButton * btn1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn1.frame = CGRectMake(100, 50, 200, 50);
    btn1.backgroundColor = [UIColor orangeColor];
    [btn1 setTitle:@"input view" forState:UIControlStateNormal];
    [btn1 addActionHandler:^(UIButton *sender, NSInteger tag) {
        [weakSelf presentViewController:[NSClassFromString(@"NEDInputViewController") new] animated:YES completion:nil];
    }];
    [self.view addSubview:btn1];
    
    
    UIButton * btn2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn2.frame = CGRectMake(100, 110, 200, 50);
    btn2.backgroundColor = [UIColor orangeColor];
    [btn2 setTitle:@"sheet 1" forState:UIControlStateNormal];
    [btn2 addActionHandler:^(UIButton *sender, NSInteger tag) {
        NEDSheetView * sheetV = [NEDSheetView new];
        [sheetV addHeadTitle:@"标题"];
        [sheetV addOptionTitle:@"菜单1" action:^(NEDSheetView * _Nonnull alertV) {
            NSLog(@"1111");
        }];
        [sheetV addOptionTitle:@"菜单2" action:^(NEDSheetView * _Nonnull alertV) {
            NSLog(@"2222");
        }];
        [sheetV addOptionTitle:@"菜单3" action:^(NEDSheetView * _Nonnull alertV) {
            NSLog(@"3333");
        }];
        [sheetV addOptionTitle:@"菜单4" action:^(NEDSheetView * _Nonnull alertV) {
            NSLog(@"4444");
        }];
        [sheetV addCancel];
        [sheetV popShow];
    }];
    [self.view addSubview:btn2];
    
    
    UIButton * btn3 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn3.frame = CGRectMake(100, 170, 200, 50);
    btn3.backgroundColor = [UIColor orangeColor];
    [btn3 setTitle:@"sheet 2" forState:UIControlStateNormal];
    [btn3 addActionHandler:^(UIButton *sender, NSInteger tag) {
        NEDSheetView * sheetV = [NEDSheetView new];
        [sheetV addHeadTitle:@"标题" description:@"副标题"];
        [sheetV addOptionTitle:@"菜单1" action:^(NEDSheetView * _Nonnull alertV) {
            NSLog(@"1111");
        }];
        [sheetV addOptionTitle:@"菜单2" action:^(NEDSheetView * _Nonnull alertV) {
            NSLog(@"2222");
        }];
        [sheetV addOptionTitle:@"菜单3" action:^(NEDSheetView * _Nonnull alertV) {
            NSLog(@"3333");
        }];
        [sheetV addOptionTitle:@"菜单4" action:^(NEDSheetView * _Nonnull alertV) {
            NSLog(@"4444");
        }];
        [sheetV addCancelBlock:^(NEDSheetItem * _Nullable passItem) {
            passItem.title = @"取消";
            passItem.titleColor = [UIColor redColor];
        } action:^(NEDSheetView * _Nonnull alertV) {
            [alertV popDismiss];
        }];
        [sheetV popShow];
    }];
    [self.view addSubview:btn3];
    
    
    UIButton * btn4 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn4.frame = CGRectMake(20, 230, 150, 50);
    btn4.backgroundColor = [UIColor orangeColor];
    [btn4 setTitle:@"alert 1" forState:UIControlStateNormal];
    [btn4 addActionHandler:^(UIButton *sender, NSInteger tag) {
        [NEDAlertView showConfig:^(NEDAlertView * _Nonnull alertView) {
      
            [alertView addHeadTitle:@"顶部标题end"];
//            [alertView addHeadBackgroundColor:[UIColor orangeColor]];
            
            [alertView addContent:@"内容区域123123内容区域123123内容区域123123内容区域123123内容区域123123内容区域123123内容区域123123内容区域123123内容区域123123end"];
            
            [alertView addBtnCloseTitle:@"知道了"];
            [alertView addBtnCloseTitle:@"好的"];
            
        }];
    }];
    [self.view addSubview:btn4];
    
    UIButton * btn4_1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn4_1.frame = CGRectMake(180, 230, 150, 50);
    btn4_1.backgroundColor = [UIColor orangeColor];
    [btn4_1 setTitle:@"alert 2" forState:UIControlStateNormal];
    [btn4_1 addActionHandler:^(UIButton *sender, NSInteger tag) {
        [NEDAlertView showConfig:^(NEDAlertView * _Nonnull alertView) {
            
            [alertView layoutConfigWithStyle:[NEDAlertLayoutConfig cornerBorderButtonStyle]];

            [alertView addHeadTitle:@"顶部标题end"];
//            [alertView addHeadBackgroundColor:[UIColor orangeColor]];
            
            [alertView addContent:@"内容区域123123内容区域123123内容区域123123内容区域123123内容区域123123内容区域123123内容区域123123内容区域123123内容区域123123end"];
            
            [alertView addBtnCloseTitle:@"知道了"];
            [alertView addBtnCloseTitle:@"好的"];
            
        }];
    }];
    [self.view addSubview:btn4_1];
    
    
    UIButton * btn5 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn5.frame = CGRectMake(100, 290, 200, 50);
    btn5.backgroundColor = [UIColor orangeColor];
    [btn5 setTitle:@"alert 2" forState:UIControlStateNormal];
    [btn5 addActionHandler:^(UIButton *sender, NSInteger tag) {
        [NEDAlertView showConfig:^(NEDAlertView * _Nonnull alertView) {
           
            [alertView layoutStyleConfig:^(NEDAlertLayoutConfig * _Nonnull config) {
                config.spaceTitleMargin = 50;
                config.showButtonsSeparationLine = YES;
                config.colorButtonsSeparationLine = [UIColor redColor];
            }];
            [alertView addHeadTitle:@"顶部标题长顶部标题长顶部标题长顶部标题长顶部标题长顶部标题长顶部标题长顶部标题长顶部标题长顶部标题长顶部标题长顶部标题长顶部标题长顶部标题长end"];
            
            [alertView addContent:@"内容区域123123 长傲红尘那个长长虹村那长虹村那长虹村那长虹村那长虹村那长虹村那end"];
            
            [alertView addBtnCloseTitle:@"多个按钮11"];
            [alertView addBtnCloseTitle:@"多个按钮22"];
            
            [alertView addBtnCloseTitle:@"多个按钮33"];
        }];
    }];
    [self.view addSubview:btn5];
    
    
    UIButton * btn6 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn6.frame = CGRectMake(100, 350, 200, 50);
    btn6.backgroundColor = [UIColor orangeColor];
    [btn6 setTitle:@"alert head bg image" forState:UIControlStateNormal];
    [btn6 addActionHandler:^(UIButton *sender, NSInteger tag) {
        [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:@"https://t7.baidu.com/it/u=1819248061,230866778&fm=193&f=GIF"] completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [NEDAlertView showConfig:^(NEDAlertView * _Nonnull alertView) {
                   
                    [alertView layoutStyleConfig:^(NEDAlertLayoutConfig * _Nonnull config) {
                        config.spaceTitleToTop = 0;
                    }];
                    [alertView addHeadBackgroundImage:image];
                    [alertView addContent:@"内容区域123123 长傲红尘那个长长虹村那长虹村那长虹村那长虹村那长虹村那长虹村那end"];
                }];
            });
        }];
    }];
    [self.view addSubview:btn6];
    
    UIButton * btn7 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn7.frame = CGRectMake(100, 410, 200, 50);
    btn7.backgroundColor = [UIColor orangeColor];
    [btn7 setTitle:@"alert custom view" forState:UIControlStateNormal];
    [btn7 addActionHandler:^(UIButton *sender, NSInteger tag) {
        [NEDAlertView showConfig:^(NEDAlertView * _Nonnull alertView) {
           
            [alertView layoutStyleConfig:^(NEDAlertLayoutConfig * _Nonnull config) {
                config.spaceTitleMargin = 50;
            }];
            [alertView addHeadTitle:@"顶部标题"];
            
//            [alertView addContent:@"内容区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红区域123123 长傲红尘长傲红尘长傲红尘长傲红v尘长傲红尘长傲红尘那个end"];
            
            UIView * customView = [UIView new];
            
            NEDInputTextField * inputView1 = [NEDInputTextField new];
            inputView1.format = [[NEDTextInputNumber alloc] initWithMaxCount:5];
            inputView1.ned_placeholder = @"最多五个";
            [inputView1 addLeftViewShowWidth:100 title:@"输入限制" withFont:14];
            [customView addSubview:inputView1];
            [inputView1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.equalTo(customView);
                make.top.offset(5);
                make.height.mas_equalTo(40);
            }];
            
            NEDInputTextField * inputView2 = [NEDInputTextField new];
            inputView2.format = [[NEDTextInputNumber alloc] initWithMaxCount:10];
            inputView2.ned_placeholder = @"最多10个";
            [inputView2 addLeftViewShowWidth:100 title:@"输入限制2222" withFont:14];
            [customView addSubview:inputView2];
            [inputView2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.equalTo(customView);
                make.top.equalTo(inputView1.mas_bottom).offset(5);
                make.height.mas_equalTo(40);
            }];
            
            [alertView addCustomView:customView contentHeight:95];
            
            [alertView addBtnCloseTitle:@"知道了"];
            [alertView addBtnCloseTitle:@"好的"];
        }];
    }];
    [self.view addSubview:btn7];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
